package com.suixuan.support.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Copyright (c) Nanjing Zhou Su co.,Ltd
 * 
 * @Project oa
 * @Title SecutiryContextFilter.java
 * @Package com.suixuan.spring.web.filter
 * @Description TODO(描述类的作用)
 * @Author suixuan
 * @Editors 1
 * @Date 2010-12-8 下午01:23:10
 * @Note
 * @Version:1.0.0
 * 
 */
public class SecutiryContextFilter implements Filter {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#destroy() Title destroy
	 * 
	 * @see javax.servlet.Filter#destroy()
	 */
	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 * javax.servlet.ServletResponse, javax.servlet.FilterChain) Title doFilter
	 * 
	 * @param arg0
	 * 
	 * @param arg1
	 * 
	 * @param arg2
	 * 
	 * @throws IOException
	 * 
	 * @throws ServletException
	 * 
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 * javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException,
			ServletException {
		// TODO Auto-generated method stub
		if (null != SecurityContextHolder.getContext()
				&& null != SecurityContextHolder.getContext().getAuthentication())
			System.out.println(SecurityContextHolder.getContext().getAuthentication().getName());
		
		arg2.doFilter(arg0, arg1);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) Title init
	 * 
	 * @param arg0
	 * 
	 * @throws ServletException
	 * 
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
	 */
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
